function Dog(name) {
    this.name = name;
    this.color = '黑色';
}
const d = new Dog('小黑');
console.log(d.color);
console.log(d.name);



function Fish(name) {
    this.name = name;
    this.color = '红色';
    return '黑色';
    // return { color: '黑色' };
}
const f = new Fish('小黑');
console.log(f);
console.log(f.color);
console.log(f.name);



//this 的指向是全局的 window 对象
function Cat(name) {
    this.name = name;
    this.color = '黑色';
}
const p = Cat('小黑');
console.log(color);
console.log(name);
console.log(p);
// console.log(p.color);
// console.log(p.name);


//实现一个new
const _new = (fn, ...rest) => {
    const nObj = Object.create(fn.prototype);
    const result = fn.call(nObj, ...rest);
    return (typeof result === 'object') ? result : nObj;
};

const myNew = _new(Dog, '小黑');
console.log(myNew.color);     // 黑色
console.log(myNew.name);    // 小黑

